from langchain_deepseek import ChatDeepSeek
from langchain.prompts import PromptTemplate

template = """提取用户输入中的日期。
用户输入:
{query}"""

prompt = PromptTemplate(
    template = template
)
query = "2024年十二月23日天气晴..."
input_prompt = prompt.format_prompt(query = query)

json_schema = {
    "title": "Date",
    "description": "Formated date expression",
    "type": "object",
    "properties": {
        "year": {
            "type": "integer",
            "description": "year, YYYY",
        },
        "month": {
            "type": "integer",
            "description": "month, MM",
        },
        "day": {
            "type": "integer",
            "description": "day, DD",
        },
        "era": {
            "type": "string",
            "description": "BC or AD",
        },
    },
}
llm = ChatDeepSeek(model="deepseek-chat", temperature=0)
structured_llm = llm.with_structured_output(json_schema)

result = structured_llm.invoke(input_prompt)
print(type(result))
print(result)